<?php
    
    namespace App\Observers;

    use App\System\Goods\Model\GoodsInfo;
    use App\System\Log\Repositories\LogAdminRepository;

    class GoodsInfoObserver
    {

        /**
         * 监听用户更新的事件。
         *
         * @param  GoodsInfo  $goodsInfo
         * @return void
         */
        public function updated(GoodsInfo $goodsInfo)
        {
            $data['type'] = 1;
            $data['log_info'] = '编辑商品详情';
            if($goodsInfo->isDirty('status')){
                if($goodsInfo->status == 1){
                    $data['log_info'] = '上架商品';
                }else{
                    $data['log_info'] = '下架商品';
                }
            }
            $logAdmin = LogAdminRepository::getInstance();
            $logAdmin->saveAdminLog($data);
        }

        /**
         * @param GoodsInfo $goodsInfo
         */
        public function created(GoodsInfo $goodsInfo)
        {
            $data['type'] = 1;
            $data['log_info'] = '新增商品';
            $logAdmin = LogAdminRepository::getInstance();
            $logAdmin->saveAdminLog($data);
        }

        /**
         * @param GoodsInfo $goodsInfo
         */
        public function deleted(GoodsInfo $goodsInfo)
        {
            $data['type'] = 1;
            $data['log_info'] = '删除商品';
            $logAdmin = LogAdminRepository::getInstance();
            $logAdmin->saveAdminLog($data);
        }

    }
     
    